Skip to content

Conversation

bend-n
Copy link
Contributor

@bend-n bend-n commented Jun 19, 2025

suggests declaring modules when a module is found but not defined, i.e

├── main.rs: `use thing::thang;`
└── thing.rs: `struct thang`

or

├── main.rs: `use thing::thang;`
└── thing
    └── mod.rs: `struct thang`

which currently is just

error[E0432]: unresolved import `yeah`
 --> src/main.rs:1:1
  |
1 | use thing::thang;
  |     ^^^^^ use of unresolved module or unlinked crate `thing`
  |

but now would have this nice help:

= help: you may have forgotten to declare the module `thing`. use `mod thing` in this file to declare this module.

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jun 19, 2025
@bend-n
Copy link
Contributor Author

bend-n commented Jun 19, 2025

@rustbot label A-diagnostics

@rustbot rustbot added the A-diagnostics Area: Messages for errors, warnings, and lints label Jun 19, 2025
@rust-log-analyzer

This comment has been minimized.

@bend-n bend-n marked this pull request as ready for review June 20, 2025 12:00
@rustbot
Copy link
Collaborator

rustbot commented Jun 20, 2025

r? @petrochenkov

rustbot has assigned @petrochenkov.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 20, 2025
@rust-log-analyzer

This comment has been minimized.

@bend-n bend-n force-pushed the suggest_declaring_modules_when_file_found_but_module_not_defined branch from 7174cb4 to 397c51b Compare June 20, 2025 13:41
@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 23, 2025
@bend-n bend-n force-pushed the suggest_declaring_modules_when_file_found_but_module_not_defined branch from c1a4a41 to 18ca511 Compare June 23, 2025 17:13
@petrochenkov petrochenkov added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 24, 2025
@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 24, 2025
@bend-n bend-n force-pushed the suggest_declaring_modules_when_file_found_but_module_not_defined branch from 18ca511 to 184ef96 Compare June 24, 2025 17:56
@petrochenkov
Copy link
Contributor

Could you also add a new test exercising the various naming schemes (like …/x/y/mod.rs and others) for the module file?

@bend-n bend-n force-pushed the suggest_declaring_modules_when_file_found_but_module_not_defined branch from 184ef96 to 2f55dce Compare June 24, 2025 18:12
@bend-n bend-n force-pushed the suggest_declaring_modules_when_file_found_but_module_not_defined branch from 2f55dce to 3583423 Compare June 24, 2025 18:13
@bend-n
Copy link
Contributor Author

bend-n commented Jun 24, 2025

Could you also add a new test exercising the various naming schemes (like …/x/y/mod.rs and others) for the module file?

im not sure how to make a test with a normal directory structure? everything seems to use #[path = auxiliary/]...

@petrochenkov
Copy link
Contributor

Well, tests/ui/modules_and_files_visibility/mod_file_disambig.rs caught some file to report, the new test can probably do something similar to that case.

@bend-n
Copy link
Contributor Author

bend-n commented Jun 26, 2025

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 26, 2025
@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 26, 2025
@bend-n bend-n force-pushed the suggest_declaring_modules_when_file_found_but_module_not_defined branch 2 times, most recently from f2c196e to 62c2fa3 Compare June 26, 2025 17:40
@bend-n
Copy link
Contributor Author

bend-n commented Jun 26, 2025

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 26, 2025
@rust-log-analyzer

This comment has been minimized.

@bend-n bend-n force-pushed the suggest_declaring_modules_when_file_found_but_module_not_defined branch from 62c2fa3 to 8fef7b9 Compare June 26, 2025 18:18
@petrochenkov
Copy link
Contributor

r=me with #142730 (comment) addressed.
@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 26, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jun 26, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@bend-n bend-n force-pushed the suggest_declaring_modules_when_file_found_but_module_not_defined branch from 8fef7b9 to 57cb419 Compare June 27, 2025 05:08
@bend-n
Copy link
Contributor Author

bend-n commented Jun 27, 2025

@bors r=petrochenkov

@bors
Copy link
Collaborator

bors commented Jun 27, 2025

@bend-n: 🔑 Insufficient privileges: Not in reviewers

@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Collaborator

bors commented Jun 27, 2025

📌 Commit 57cb419 has been approved by petrochenkov

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 27, 2025
bors added a commit that referenced this pull request Jun 27, 2025
Rollup of 9 pull requests

Successful merges:

 - #139858 (New const traits syntax)
 - #140809 (Reduce special casing for the panic runtime)
 - #142730 (suggest declaring modules when file found but module not defined)
 - #142806 (Normalize before computing ConstArgHasType goal in new solver)
 - #143046 (const validation: properly ignore zero-sized UnsafeCell)
 - #143092 (const checks for lifetime-extended temporaries: avoid 'top-level scope' terminology)
 - #143096 (tag_for_variant: properly pass TypingEnv)
 - #143104 (hir_analysis: prohibit `dyn PointeeSized`)
 - #143106 (gce: don't ICE on non-local const)

Failed merges:

 - #143036 (Remove support for `dyn*` from the compiler)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 190a1a7 into rust-lang:master Jun 28, 2025
10 checks passed
@rustbot rustbot added this to the 1.90.0 milestone Jun 28, 2025
rust-timer added a commit that referenced this pull request Jun 28, 2025
Rollup merge of #142730 - bend-n:suggest_declaring_modules_when_file_found_but_module_not_defined, r=petrochenkov

suggest declaring modules when file found but module not defined

suggests declaring modules when a module is found but not defined, i.e
```
├── main.rs: `use thing::thang;`
└── thing.rs: `struct thang`
```
or
```
├── main.rs: `use thing::thang;`
└── thing
    └── mod.rs: `struct thang`
```
which currently is just
```rust
error[E0432]: unresolved import `yeah`
 --> src/main.rs:1:1
  |
1 | use thing::thang;
  |     ^^^^^ use of unresolved module or unlinked crate `thing`
  |
```
but now would have this nice help:
```text
= help: you may have forgotten to declare the module `thing`. use `mod thing` in this file to declare this module.
```
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Jun 28, 2025
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#139858 (New const traits syntax)
 - rust-lang/rust#140809 (Reduce special casing for the panic runtime)
 - rust-lang/rust#142730 (suggest declaring modules when file found but module not defined)
 - rust-lang/rust#142806 (Normalize before computing ConstArgHasType goal in new solver)
 - rust-lang/rust#143046 (const validation: properly ignore zero-sized UnsafeCell)
 - rust-lang/rust#143092 (const checks for lifetime-extended temporaries: avoid 'top-level scope' terminology)
 - rust-lang/rust#143096 (tag_for_variant: properly pass TypingEnv)
 - rust-lang/rust#143104 (hir_analysis: prohibit `dyn PointeeSized`)
 - rust-lang/rust#143106 (gce: don't ICE on non-local const)

Failed merges:

 - rust-lang/rust#143036 (Remove support for `dyn*` from the compiler)

r? `@ghost`
`@rustbot` modify labels: rollup
flip1995 pushed a commit to flip1995/rust-clippy that referenced this pull request Jul 10, 2025
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#139858 (New const traits syntax)
 - rust-lang/rust#140809 (Reduce special casing for the panic runtime)
 - rust-lang/rust#142730 (suggest declaring modules when file found but module not defined)
 - rust-lang/rust#142806 (Normalize before computing ConstArgHasType goal in new solver)
 - rust-lang/rust#143046 (const validation: properly ignore zero-sized UnsafeCell)
 - rust-lang/rust#143092 (const checks for lifetime-extended temporaries: avoid 'top-level scope' terminology)
 - rust-lang/rust#143096 (tag_for_variant: properly pass TypingEnv)
 - rust-lang/rust#143104 (hir_analysis: prohibit `dyn PointeeSized`)
 - rust-lang/rust#143106 (gce: don't ICE on non-local const)

Failed merges:

 - rust-lang/rust#143036 (Remove support for `dyn*` from the compiler)

r? `@ghost`
`@rustbot` modify labels: rollup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants